import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

import path from "path";

// Element Plus 按需加载
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// jsx支持
import vueJsx from '@vitejs/plugin-vue-jsx';

// https://vite.dev/config/
export default defineConfig({
  // 打包quickAdmin 框架
  build:{
    cssCodeSplit:true,
    lib:{
      entry:'./src/components/build.ts',
      name:'quickApp',
      fileName: (format) => `qa.${format}.js`,
    },
    rollupOptions:{
      external:['vue','element-plus'],
      output:{
        globals:{
          vue:'Vue',
          'element-plus':'ElementPlus'
        }
      },
    },
  },

  resolve:{
    alias:{
      '@':path.resolve(__dirname,'src')
    }
  },
  plugins: [vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    AutoImport({
      imports: ['vue', 'vue-router'],
      dts: 'auto-imports.d.ts',
    }),
    Components({
      dirs: [], // 不扫描任何文件夹自动引入
      resolvers: [ElementPlusResolver()],
    }),
    vueJsx(),
  ],
  server:{
    proxy:{
      '/api':{
        target:'http://localhost:3000',
        changeOrigin:true,
        rewrite:(path)=>path.replace(/^\/api/,'')
      }
    }
  }
})
